<template>
    <view class="content">
        <view class="item" v-for="(item, index) in list" :key="index" @click="toDetails(item)">
            <image :src="item.image" class="img"></image>
            <view class="item-right">
                <view class="name">{{item.title}}</view>
                <view class="sub">{{item.describes}}</view>
                <view class="btns" v-if="type == 1 && item.type == 1">
                    <view class="cy-btn">立即参与</view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                type: 0,
                id: '',
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onLoad(option) {
            if (option.id) {
                this.id = option.id
            }
            this.type = option.type
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            toDetails(item) {
                // item.type 1图文 2链接
                if (item.type == 1) {
                    this.$gTo(`/pages/classroom/classroom-details?id=${item.id}&type=${this.type}`)
                } else if (item.type == 2) {
                    uni.navigateToMiniProgram({
                        appId: item.link,
                    })
                }
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('activity_list', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    type: this.type,//1活动 2艺术班 3实时计划全部 4实时计划我的
                    type_id: this.id,//活动分类id
            	}).then(ret => {
            		if (ret.success == 1000) {
            			if (ret.detail && ret.detail.activity && ret.detail.activity.length > 0) {
            				this.list = this.list.concat(ret.detail.activity);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    page{
        background-color: #fff;
        border-top: 2rpx solid #eee;
    }
    .content{
        padding: 0 25rpx;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 35rpx 0;
    }
    .img{
        width: 165rpx;
        height: 165rpx;
        border-radius: 10rpx;
        margin-right: 25rpx;
    }
    .item-right{
        width: 510rpx;
    }
    .name{
        font-size: 32rpx;
        font-weight: bold;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-bottom: 8rpx;
    }
    .sub{
        font-size: 24rpx;
        color: #949494;
        line-height: 32rpx;
        height: 64rpx;
        word-break: break-all;
        white-space: pre-line;
        display: -webkit-box;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    .btns{
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .cy-btn{
        padding: 12rpx 23rpx;
        font-size: 26rpx;
        color: #000;
        border-radius: 6rpx;
        background-color: #fec427;
        margin-top: 10rpx;
    }

</style>
